package com.shuhe.metastore;

import com.shuhe.JettyServer;
import org.apache.log4j.Logger;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class AISql {

    private static Logger logger = Logger.getLogger(AISql.class);

    private static String url = JettyServer.globalProperties.getProperty("ai.url");
    private static String username = JettyServer.globalProperties.getProperty("ai.user");
    private static String password = JettyServer.globalProperties.getProperty("ai.password");
    private static String driver = JettyServer.globalProperties.getProperty("ai.driver");


    public static ResultSet querySql(Connection conn, String sql) throws Exception {
        logger.info(sql);
        return conn.createStatement().executeQuery(sql);
    }

    public static Connection connect() throws Exception {
        Class.forName(driver);
        return DriverManager.getConnection(url, username, password);
    }

    public static int execSql(Connection conn, String sql) throws Exception {
        logger.info(sql);
        return conn.createStatement().executeUpdate(sql);
    }

}
